<template>
  <div class="dayin">
    <el-button type="primary" @click="print()" class="dayin_btn" v-if="isprint"
      >打印预览</el-button>
    <div ref="print" id="printArea">
      <div v-for="(items, indexs) in dayinlist" :key="indexs"> 
      <div class="box_bg" v-for="(item, index) in items.order_second" :key="index">
        <div v-for="(ite, ind) in item.num" :key="ind" class="div_ccc">
          <div class="right">
            <div class="center">
              <span>{{item.model_number ? item.model_number.model_number : ""}}</span>
              <span>{{item.specification ? item.specification.specification : ""
}}</span>
              <span>{{ item.color ? item.color.color : "" }}</span>
              <span>{{ customer_name }}</span>
            </div>
          </div>
          <div style="page-break-after: always"></div>
        </div>
      </div>
    </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      dayinlist: [],
      order_second: [],
      imageUrl: "",
      strDate: "",
      erweitext: "",
      isprint: true,
      Infomation: "",
      customer_name: "",
    };
  },
  mounted() {
    this.dayinlist = JSON.parse(this.$route.query.data);
    this.Infomation = this.$store.getters.Infomation.company_name;
    console.log(this.order_second);
  },
  methods: {
    print() {
      // this.isprint=false
      this.$print(this.$refs.print);
    },
    /**
     * 获取当前时间
     */
    currentTime() {
      var date = new Date();
      var year = date.getFullYear(); //月份从0~11，所以加一
      let month = date.getMonth();
      console.log("month", month);
      var dateArr = [
        date.getMonth() + 1,
        date.getDate(),
        date.getHours(),
        date.getMinutes(),
        date.getSeconds(),
      ];
      //如果格式是MM则需要此步骤，如果是M格式则此循环注释掉
      for (var i = 0; i < dateArr.length; i++) {
        if (dateArr[i] >= 1 && dateArr[i] <= 9) {
          dateArr[i] = "0" + dateArr[i];
        }
      }
      this.strDate =
        year +
        "/" +
        dateArr[0] +
        "/" +
        dateArr[1] +
        " " +
        dateArr[2] +
        ":" +
        dateArr[3] +
        ":" +
        dateArr[4];
    },
  },
};
</script>
<style scoped>
#printArea {
  width: 100%;
  margin: 0 auto;
}

.dayin_btn {
  background: #0a8fa1;
  border: none;
  margin: 20px 0;
}

.box_bg {
  width: 210mm;
}

.box_bg .div_ccc {
  width: 210mm;
  height: 140mm;
  background: url(../../assets/img_bgs.jpg);
  background-size: 100% 100%;
  display: flex;
  justify-content: space-between;
  position: relative;
}

.box_bg .right {
  width: 110mm;
  height: 132mm;
  position: absolute;
  right: 10mm;
}
.box_bg .right .center {
  width: 67mm;
  height: 80mm;
  position: absolute;
  top:15mm;
  right: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  font-weight: bold;
  font-size: 25px;
}
.box_bg .right .center span {
  display: block;
  height: 20mm;
}

@media print {
  #printArea {
    width: 100%;
  }
  /* .box_bg {
    width: 210mm;
    height: 140mm;
    background: url(../../assets/img_bgs.jpg);
    background-size: 100% 100%;
    display: flex;
    justify-content: space-between;
    position: relative;
  } */

  .box_bg {
    width: 210mm;
  }

  .box_bg .div_ccc {
    width: 210mm;
    height: 140mm;
    background: url(../../assets/img_bgs.jpg);
    background-size: 100% 100%;
    display: flex;
    justify-content: space-between;
    position: relative;
    /* border: 1px solid #000; */
  }
  .box_bg .right {
    width: 110mm;
    height: 132mm;
    position: absolute;
    right: 10mm;
  }

  .box_bg .right .center {
    width: 67mm;
    height: 80mm;
    position: absolute;
    top:15mm;
    right: 0;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    font-weight: bold;
    font-size: 25px;
  }
  .box_bg .right .center span {
    display: block;
    height: 20mm;
    line-height: 20mm;
    /* border: 1px solid #000; */
  }
}
</style>
